﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentSpotItemVMs
{
    public partial class EquipmentSpotItemListVM : BasePagedListVM<EquipmentSpotItem_View, EquipmentSpotItemSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipmentSpotItem_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentSpotItem_View>>{
                
                this.MakeGridHeader(x => x.EquipmentSpotItem_Template).SetTitle(@Localizer["Page.模板"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotItem_SpotType).SetTitle(@Localizer["Page.点检类型"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotItem_Content).SetTitle(@Localizer["Page.点检内容"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotItem_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotItem_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotItem_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotItem_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotItem_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotItem_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentSpotItem_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentSpotItem>()
                
                .CheckEqual(Searcher.TemplateId, x=>x.TemplateId)
                .CheckEqual(Searcher.SpotType, x=>x.SpotType)
                .CheckContain(Searcher.Content, x=>x.Content)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EquipmentSpotItem_View
                {
				    ID = x.ID,
                    
                    EquipmentSpotItem_Template = x.Template.Name,
                    EquipmentSpotItem_SpotType = x.SpotType,
                    EquipmentSpotItem_Content = x.Content,
                    EquipmentSpotItem_Active = x.Active,
                    EquipmentSpotItem_CreateTime = x.CreateTime,
                    EquipmentSpotItem_UpdateTime = x.UpdateTime,
                    EquipmentSpotItem_CreateBy = x.CreateBy,
                    EquipmentSpotItem_UpdateBy = x.UpdateBy,
                    EquipmentSpotItem_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipmentSpotItem_View: EquipmentSpotItem
    {
        
        public string EquipmentSpotItem_Template { get; set; }
        public SpotTypeEnum? EquipmentSpotItem_SpotType { get; set; }
        public string EquipmentSpotItem_Content { get; set; }
        public bool? EquipmentSpotItem_Active { get; set; }
        public DateTime? EquipmentSpotItem_CreateTime { get; set; }
        public DateTime? EquipmentSpotItem_UpdateTime { get; set; }
        public string EquipmentSpotItem_CreateBy { get; set; }
        public string EquipmentSpotItem_UpdateBy { get; set; }
        public bool EquipmentSpotItem_IsValid { get; set; }

    }

}